package com.android.lovepick.util;

import java.util.List;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.lovepick.R;

public class ChatListAdapter extends BaseAdapter
{
	private List<ChatList> mChatLists = null;
	private Context mContext;
	private LayoutInflater mInflater;

	public ChatListAdapter(Context context, List<ChatList> list)
	{
		this.mContext = context;
		this.mChatLists = list;
		mInflater = LayoutInflater.from(mContext);
	}

	public int getCount()
	{
		// TODO Auto-generated method stub
		return mChatLists.size();
	}

	public Object getItem(int position)
	{
		// TODO Auto-generated method stub
		return mChatLists.get(position);
	}

	public long getItemId(int position)
	{
		// TODO Auto-generated method stub
		return position;
	}

	public View getView(int position, View convertView, ViewGroup parent)
	{
		// TODO Auto-generated method stub
		ViewHolder viewHolder = null;
		ChatList chatList = mChatLists.get(position);

		if (null == convertView)
		{
			convertView = mInflater.inflate(R.layout.chatlist_item, null);
			viewHolder = new ViewHolder();
			viewHolder.imvUserface = (ImageView) convertView
					.findViewById(R.id.img_chatlist_userface);
			viewHolder.txvNickName = (TextView) convertView
					.findViewById(R.id.txv_chatlist_from);
			viewHolder.txvMsgSummary = (TextView) convertView
					.findViewById(R.id.txv_chatlist_summary);
			viewHolder.txvDate = (TextView) convertView
					.findViewById(R.id.txv_chatlist_date);

		}
		else
		{
			viewHolder = (ViewHolder) convertView.getTag();
		}

		viewHolder.imvUserface.setImageDrawable(chatList.getUserface());
		viewHolder.txvNickName.setText(chatList.getNickName());
		viewHolder.txvMsgSummary.setText(chatList.getMsgSummary());
		viewHolder.txvDate.setText(chatList.getDate());
		return convertView;
	}

	static class ViewHolder
	{
		public ImageView imvUserface;
		public TextView txvNickName;
		public TextView txvMsgSummary;
		public TextView txvDate;
	}

}
